import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const routes = [
    { path: '/', redirect: '/home' },

    // 登录
    { path: '/login', component: () =>
    import ( /* webpackChunkName: "about" */ '../views/login.vue') },
    
    //主页
    {
      path: '/home',
      name: 'Home',
      component: () =>
      import ( /* webpackChunkName: "about" */ '../views/Home.vue')
    },
    
    //商品列表
    {
      path: '/prolist',
      name: 'Prolist',
      component: () =>
      import ( /* webpackChunkName: "about" */ '../views/Prolist.vue')
    },
    
    //订单列表
    {
      path: '/orderlist',
      name: 'Orderlist',
      component: () =>
      import ( /* webpackChunkName: "about" */ '../views/OrderList.vue')
    },
    
    //退货申请处理
    {
      path: '/reApplyHandle',
      name: 'reApplyHandle',
      component: () =>
      import ( /* webpackChunkName: "about" */ '../views/ReAppHand.vue')
    },
    
    // 秒杀链接
    {
      path: '/spike',
      name: 'Spike',
      component: () =>
      import ('@/views/Spike.vue'),
    },
    
    // 优惠券链接
    {
      path: '/coupon',
      name: 'Coupon',
      component: () =>
      import ('@/views/Coupon.vue')
    },
    
    // 广告链接
    {
 
        path: '/advertising',
        name: 'Advertising',
        component: () =>
            import ('@/views/Advertising.vue'),
    },

    //品牌
    {
        path: '/brand',
        name: 'Brand',
        component: () =>
            import ('../views/Brand.vue'),
    },

    //新品
    {
        path: '/product',
        name: 'Product',
        component: () =>
            import ('../views/Product.vue'),
    },

    //人气
    {
        path: '/popularity',
        name: 'Popularity',
        component: () =>
            import ('../views/Popularity.vue'),
    },

    //专题
    {
        path: '/subject',
        name: 'subject',
        component: () =>
            import ('../views/Subject.vue'),
    },

    //订单设置
    {
        path: '/orderset',
        name: 'orderset',
        component: () =>
            import ("../views/Orderset.vue")
    },

    //退货原因设置
    {
        path: '/Returnreasonset',
        name: 'Returnreasonset',
        component: () =>
            import ("../views/Returnreasonset.vue")
    },

    //资源列表
    {
        path: '/Permissionlist',
        name: 'Permissionlist',
        component: () =>
            import ("../views/Permissionlist.vue")
    },

    // 添加商品
    {
        path: '/addProduct',
        name: 'AddProduct',
        component: () =>
            import ('../views/addProduct.vue'),
    },
    //秒杀时间段列表
    {
        path: '/flashSession',
        name: 'flashSession',
        component: () =>
            import ('@/views/miaoSession.vue')
    },
    //秒杀活动列表——————设置商品路由
    {
        path: '/selectSession',
        name: 'selectSession',
        component: () =>
            import ('@/views/selectSession.vue')
    },
         // 用户列表
         {
          path: '/user',
          name: 'user',
          component: () => import('../views/User.vue')
        },
        // 角色列表
        {
          path: '/role',
          name: 'role',
          component: () => import('../views/role.vue')
        },
         // 菜单列表
         {
          path: '/menu',
          name: 'menu',
          component: () => import('../views/menu.vue')
        },
        {
            path: '/goodType',
            name: 'goodType',
            component: () =>
              import('../views/goodType.vue'),
          },
          {
            path: '/productMain',
            name: 'productMain',
            component: () =>
              import('../views/productMain.vue'),
          },
          {
            path: '/brands',
            name: 'brands',
            component: () =>
              import('../views/brands.vue'),
          },
          {
            path: '/addProductCate',
            name: 'addProductCate',
            component: () =>import('@/views/addProductCate.vue'),
          },
          {
            path: '/addBrands',
            name: 'addBrands',
            component: () =>
              import('../views/addBrands.vue'),
          },
]


const router = new VueRouter({
        routes
    })
    // 挂载路由导航守卫,to表示将要访问的路径，from表示从哪里来，next是下一个要做的操作 next('/login')强制跳转login
router.beforeEach((to, from, next) => {
    // 访问登录页，放行
    if (to.path === '/login') return next()
        // 获取token
    var tokenStr = window.sessionStorage.getItem('token')
        // 没有token, 强制跳转到登录页
    if (!tokenStr) return next('/login')
    next()
})
export default router